package com.zhuiji7.filedownloader.download;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;

import com.efounder.util.AppContext;
import com.utilcode.util.ServiceUtils;

/**
 * 类功能描述：下载器后台服务</br>
 *
 * @author zhuiji7  (470508081@qq.com)
 * @version 1.0
 * </p>
 */
public class DownLoadService extends Service {

    private static DownLoadManager downLoadManager;

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    public static DownLoadManager getDownLoadManager() {
        boolean serviceRunning = ServiceUtils.isServiceRunning(DownLoadService.class);
        if (!serviceRunning) {
            AppContext.getInstance().startService(new Intent(AppContext.getInstance(), DownLoadService.class));
        }
        if (downLoadManager == null) {
            downLoadManager = new DownLoadManager(AppContext.getInstance());
        }
        return downLoadManager;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        //释放downLoadManager
        if (downLoadManager!=null){
            try {
                downLoadManager.stopAllTask();
            } catch (Exception e) {
                e.printStackTrace();
            }
            downLoadManager = null;
        }


    }

}
